package com.fatmeraid.controller.product;


import com.fatmeraid.common.model.PageResult;
import com.fatmeraid.common.result.Result;
import com.fatmeraid.domain.ProductType;
import com.fatmeraid.service.ProductTypeService;
import com.fatmeraid.vo.PaginationVo;
import com.fatmeraid.vo.productType.TypeAddVo;
import com.fatmeraid.vo.productType.TypeUpdateVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品类型管理管理")
@RestController
@RequestMapping("/productType")
public class ProductTypeController {

	@Autowired
	private ProductTypeService productTypeService;

	@Operation(summary = "上传商品类型")
	@PostMapping
	public Result<String> uploadProductType(@RequestBody TypeAddVo typeAddVo){
		Boolean ret =productTypeService.uploadProductType(typeAddVo);
		if(!ret){
			return Result.fail();
		}
		return Result.ok();
	}
	@Operation(summary = "获取商品类型列表")
	@GetMapping
	public Result<PageResult<ProductType>> getProductTypeList( PaginationVo paginationVo){
		PageResult<ProductType> list = productTypeService.getProductTypeList(paginationVo);
		return Result.ok(list);
	}


	@Operation(summary = "修改商品类型")
	@PutMapping
	public Result<String> updateProductType(@RequestBody TypeUpdateVo typeUpdateVo){
		boolean ret = productTypeService.updateProductType(typeUpdateVo);
		if (!ret){
			return Result.fail();
		}
		return Result.ok();
	}


}
